<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrderPaymentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('order_payments', function (Blueprint $table) {
            $table->increments('id');
            $table->string('payment_sn')->comment('支付单号');
            $table->string('order_sn')->comment('订单编号');
            $table->string('pay_mode')->comment('支付类型 wxpay 微信支付; alipay 支付宝支付；balance 余额支付；score: 积分支付');
            $table->string('status')->comment('支付状态 wait_pay 待支付；paid 已支付；refund 已退款');
            $table->float('money')->comment('支付金额');
            $table->string('out_trade_sn')->comment('第三方支付单号');
            $table->timestamp('paid_at')->nullable()->comment('支付时间');
            $table->timestamps();

            $table->unique('payment_sn');
            $table->index('order_sn');

            $table->foreign('order_sn')->references('order_sn')->on('orders');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('order_payments');
    }
}
